<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>字符串</title>
</head>

<body>
    <script>
        // 1、字符串声明
        let myStr = '';
        let myStr1 = "Hello JS";
        let myStr2 = `
            可换行的字符串，'SSSS', "KKKKK"，<h1>这是H1标题</h1>
        `;
        console.log(myStr1);
        console.log(myStr2);

        let myStr3 = `可以作为模板字符串，${myStr1}！！`;
        console.log(myStr3);

        // 2、遍历
        console.log("=========1===============");

        for (let i = 0; i < myStr1.length; i++) {
            console.log(i + " => " + myStr1[i]);
        }

        console.log("=========2===============");

        for (let k in myStr1) {
            console.log(k);
        }

        console.log("=========3===============");

        for (let val of myStr1) {
            console.log(val);
        }

        // 3、方法
        console.log(myStr1.substring(1, 5));
        console.log(myStr1.slice(1, 5));

        console.log(myStr1.toLowerCase());

        console.log(myStr1.toUpperCase());

        let newStr = "kk=123";
        console.log(newStr.split('='))


        // 4、回文字符串判断
        let huiStr = "abcd";

        // 4-1: 字符串比较
        let newArr = huiStr.split('');
        newArr.reverse();
        let newHuiStr = newArr.join('');
        // let newHuiStr = huiStr.split('').reverse().join('');

        if (newHuiStr == huiStr) {
            console.log("OK");
        } else {
            console.log("NOT!");
        }

        // 4-2：循环
        let flag = true;
        for (let i = 0, k = huiStr.length - 1; i < k; i++, k--) {
            if (huiStr[i] != huiStr[k]) {
                flag = false;
                break;
            }
        }

        if (flag) {
            console.log("OK");
        } else {
            console.log("NOT!");
        }



    </script>
</body>

</html>